package com.simon.codepiece.serializable.fastjson;

import java.nio.charset.Charset;
/**
 * 
 * ps:其实fastjson api非常方便，直接使用就好，封装只是为替换留后路而已
 *
 */
public class JsonSerializerUtil {
	
	private final Charset charset;

	public JsonSerializerUtil() {
		this(Charset.forName("UTF8"));
	}

	public JsonSerializerUtil(Charset charset) {
		// Assert.notNull(charset);
		this.charset = charset;
	}

	public byte[] serialize(Object t) {
		String string = String.valueOf(t);
		return (string == null ? null : string.getBytes(charset));
	}

	public Object deserialize(byte[] bytes) {
		return (bytes == null ? null : new String(bytes, charset));
	}

}
